import { Component,HostListener,HostBinding, OnInit } from '@angular/core';
// import { DataService } from './data.service';
import 'rxjs/Rx';
import {Http, Headers} from "@angular/http";
import { Router,
  NavigationExtras } from '@angular/router';
 import { ShowHead } from "./show-head.directive";
import { MessageService } from './message.service'

 import { ShowBottom } from "./show-bottom.directive";
 import { DataService } from "./data.service";
@Component({
  moduleId: module.id,
  selector: 'app-root',
  templateUrl: 'app.component.html',
 directives:[ShowHead,ShowBottom],
  styleUrls: ['app.component.css']

})
export class AppComponent implements OnInit {
lastUpdated:any;
  array = [];
  toposition =false;
  sum = 3;
  yy = [];
  ii = [];
  msglist:any=[1,2,3,4,5,6];
    p:any=0;
     t=0;
  title = "";
  constructor(public http: Http,public router: Router,public mg:MessageService,public ds:DataService) {
        var mnnn;
    this.msglist = 990;
    
    
   var xx = mg.getmessage() ;



 if(typeof xx.cover === 'function') {
     var yy = ds.getLiveCover(function(data){
    //this.ii = data.data.liveElements;
    console.log('dog in',data);
   console.log("who let the dog out",xx.cover(data.data));


   });

   //var bb = xx.cover(this.ii);

}
 if(typeof xx.format === 'function') {
   var shitt = [];
     var yy = ds.getData(function(data){
    //this.ii = data.data.liveElements;
    console.log('cat in ing ',data.data.liveElements[0]);
   console.log("who let the cat out",xx.format(data.data.liveElements,301));
shitt =xx.format(data.data.liveElements,301);
mnnn = shitt;
console.log('what going on?',mnnn);
    this.msglist = mnnn;

   }.bind(this));
 
}
     this.msglist = mnnn;
     console.log("right",this.msglist)
}


  //  setTimeout(function(){this.t = this.p;},0);
  onScrollDown() {
    console.log('hey are you here ???', this.msglist);
    console.log('scrolled!!');
    const start = this.sum;
    this.sum += 1;
    for (let i = start; i < this.sum; ++i) {
      let b = this.yy[i];
      console.log("test", b);
      this.array.push(this.yy[i]);
    }
  }

    ngOnInit() {

  }
}

